#!/usr/bin/python

"""first.py
Copyright (C) 2009  Ryan Box

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>."""


__author__ = "Ryan Box (coffebean@sbcglobal.net)"
__version__ = "$Revision: 0.0.1 $"
__date__ = "$Date: 12/01/09 $"
__license__ = "Python"

import os
import os.path
import time
from configobj import ConfigObj
from time import asctime


##TO-DO remove test from all rsync t-backuptest.log
#-----------------------------Variables-----------------------------------------
"""If used as a cron job this must be changed to the full path to the file in
your home directory, or where you extracted the folder"""
config = ConfigObj('/home/coffeeboy/Projects/google_code/savethehouse/src/config.ini')

backupruntime = asctime()

backupmedia = config['media']

#sourcedir = config['source']

#backupdir = backupmedia + config['backupdir']

incrementsdir = backupmedia + config['incsdir']

log = backupmedia + config['logfile']

#backupincdir = incrementsdir + backupruntime

def back(backupdir='os.listdir'):
    """Create the backup Directory on the first run."""
    backuplog = open(log, 'a')
    print >> backuplog, ('#' * 80)
    print >> backuplog, ('#' * 80)
    print >> backuplog, ('\n')
    print >> backuplog, ('Starting New Backup Scheme'' '+backupruntime+':')
    print >> backuplog, ('\n')

    if not os.path.exists(backupdir):
	print 'The backup directory dose not exist. Creating now.'
	print >> backuplog, ('The backup directory dose not exist. Creating now.')
	print >> backuplog, ('\n')
	os.mkdir(backupdir)
    time.sleep(5)

def increm(incrementsdir='os.listdir'):
    """Create the Increments Directory on the first run."""
    backuplog = open(log, 'a')
    print >> backuplog, ('#' * 80)
    print >> backuplog, ('\n')
    if not os.path.exists(incrementsdir):
	print 'The increments directory dose not exist. Creating now.'
	print >> backuplog, ('The increments directory dose not exist. Creating now.')
	print >> backuplog, ('\n')
	os.mkdir(incrementsdir)

    print >> backuplog, ('#' * 80)
    print >> backuplog, ('#' * 80)
    print >> backuplog, ('\n')
    time.sleep(5)